using UnityEngine;
using UnityEngine.SceneManagement;

public class GameOverManager : MonoBehaviour
{
    public static GameOverManager Instance { get; private set; }

    [Header("Scene Settings")]
    [SerializeField] private string gameOverSceneName = "GameOver";

    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }

    public void ShowGameOver()
    {
        SaveGameStats();
        Time.timeScale = 1f;
        SceneManager.LoadScene(gameOverSceneName);
    }

    private void SaveGameStats()
    {
        if (ProgressiveWaveManager.Instance != null)
        {
            int wavesCompleted = ProgressiveWaveManager.Instance.GetWavesCompleted();
            PlayerPrefs.SetInt("LastWavesCompleted", wavesCompleted);

            int currentWave = ProgressiveWaveManager.Instance.GetCurrentWave();
            PlayerPrefs.SetInt("LastCurrentWave", currentWave);

            int totalZombiesKilled = ProgressiveWaveManager.Instance.GetTotalZombiesKilled();
            PlayerPrefs.SetInt("LastZombiesKilled", totalZombiesKilled);

            PlayerPrefs.Save();
        }
    }

    #region Public Static Getters
    public static int GetLastWavesCompleted()
    {
        return PlayerPrefs.GetInt("LastWavesCompleted", 0);
    }

    public static int GetLastCurrentWave()
    {
        return PlayerPrefs.GetInt("LastCurrentWave", 0);
    }

    public static int GetLastZombiesKilled()
    {
        return PlayerPrefs.GetInt("LastZombiesKilled", 0);
    }
    #endregion
}